package ntd.util.frame.action.zzfm.fk.hk;

import cn.hutool.db.Entity;
import cn.hutool.log.StaticLog;
import ntd.action.ActionAbs;
import ntd.action.bo.ActionInfo;
import ntd.action.bo.ActionOutBo;
import ntd.util.config.common.enums.EnumPlatformType;
import ntd.util.frame.data.factory.FactoryData;
import ntd.util.frame.data.tool.ToolMysql;
import ntd.util.modular.function.entity.ChannelBusiness;
import ntd.util.modular.function.util.UtilChannelBusiness;

public class ActionZzfmFkHkStatus extends ActionAbs {

    @Override
    public ActionInfo info() {
        return new ActionInfo("富铭-反控-海控平台-微曝-状态", "action-zzfm-fk-hk-status", new ActionZzfmFkHkStatus(), EnumPlatformType.HAIKONG.getValue());
    }

    @Override
    public ActionOutBo handle() {
        String dataCode = actionInBo.getDataCode();

        ToolMysql toolMysql = new ToolMysql(FactoryData.dataSource());

        // 获取设备信息
        Entity deviceEntity = toolMysql.findOne("things_device", "id", dataCode);
        // 获取产品信息
        Entity productEntity = toolMysql.findOne("things_product", "id", deviceEntity.getStr("product_id"));
        // 获取渠道信息
        ChannelBusiness channelBusiness = UtilChannelBusiness.getById(productEntity.getStr("channel_id"));

        RemoteHk remoteHk = new RemoteHk(channelBusiness.getEndpoint(), channelBusiness.getAppKey(), channelBusiness.getAppSecret(), productEntity.getStr("key"));

        String code = deviceEntity.getStr("code");

        String rly1 = remoteHk.getProperty(code, "rly1");

        StaticLog.info("微曝设备[{}]状态[{}]", code, rly1);

        return new ActionOutBo(rly1);
    }
}
